package com.startery.template;

import org.springframework.data.redis.core.BoundHashOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

import com.startery.ConnectionFactory;

public class HashTest {
	
	
	
	public static void main(String[] args) {
		RedisTemplate<Object, Object> redisTemplate = new RedisTemplate<Object, Object>();

        //使用Jackson2JsonRedisSerializer来序列化和反序列化redis的value值
        redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());
        redisTemplate.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());

        //使用StringRedisSerializer来序列化和反序列化redis的ke
        redisTemplate.setKeySerializer(new StringRedisSerializer());
        redisTemplate.setHashKeySerializer(new GenericJackson2JsonRedisSerializer());

        //开启事务
        redisTemplate.setEnableTransactionSupport(true);
        redisTemplate.setConnectionFactory(ConnectionFactory.getInstance());
        redisTemplate.afterPropertiesSet();
        
        //与某一个key进行绑定
        BoundHashOperations<Object, Object, Object> boundHashOperations = redisTemplate.boundHashOps("bim.set:li");  
        boundHashOperations.put("ww","i");  
        boundHashOperations.put("w1","i1");  
        boundHashOperations.put("w2","i2");  
        
        //获得绑定的key
        System.out.println("获取设置的绑定key值:" + boundHashOperations.getKey());
	
	}

	
}
